import pandas as pd
from .feature_decorator import support_predict

@support_predict
def prepare_features(df):
    """将时间转换为连续的月份数作为特征"""
    dates = pd.to_datetime(df.iloc[:, 0])
    start_date = dates.min()
    
    # 计算每个日期距离起始日期的月份数
    months_since_start = ((dates.dt.year - start_date.year) * 12 + 
                         (dates.dt.month - start_date.month))
    
    # 将特征转换为二维数组
    X = months_since_start.values.reshape(-1, 1)
    y = df.iloc[:, 1].values
    return X, y